package gui.panel;

import gui.other.JComponentCellRenderer;
import j_util.Utiles;
import model.TruthTable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Extension de JPanel, referido a la funcionalidad y visualizacion de tabla de verdad.
 * Codigo poco mantenible, se considera su eliminacion en algun momento;
 * @author Jose Martin Rozanec;
 * @deprecated;
 */
public class TruthTablePanel extends JPanel {
    private javax.swing.JButton acceptButton;
    private javax.swing.JButton bicondicionalButton;
    private javax.swing.JButton calcularTabla;
    private javax.swing.JButton resetButton;
    private javax.swing.JButton condicionalButton;
    private javax.swing.JButton conjuncionButton;
    private javax.swing.JPanel cuadroPanel;
    private javax.swing.JButton disyuncionExcButton;
    private javax.swing.JButton disyuncionIncButton;
    private javax.swing.JButton incompatibilidadButton;
    private javax.swing.JTextField inputTextField;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton negacionButton;
    private javax.swing.JButton negacionConjuntaButton;
    private javax.swing.JPanel operadoresPanel;
    private javax.swing.JTable table;
    private javax.swing.JLabel variableIngresarLabel;

    private List<String> tableTitles;
    private TruthTable truthTable;

    public TruthTablePanel() {
        tableTitles = new ArrayList<String>();
        initComponents();
    }

    private void initComponents() {
        mainPanel = new javax.swing.JPanel();
        cuadroPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        table = new javax.swing.JTable();
        operadoresPanel = new javax.swing.JPanel();
        negacionButton = new javax.swing.JButton();
        conjuncionButton = new javax.swing.JButton();
        disyuncionIncButton = new javax.swing.JButton();
        disyuncionExcButton = new javax.swing.JButton();
        condicionalButton = new javax.swing.JButton();
        bicondicionalButton = new javax.swing.JButton();
        negacionConjuntaButton = new javax.swing.JButton();
        incompatibilidadButton = new javax.swing.JButton();
        inputTextField = new javax.swing.JTextField();
        variableIngresarLabel = new javax.swing.JLabel();
        acceptButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        calcularTabla = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();

        mainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true), "Tabla de verdad"));

        cuadroPanel.setBackground(new java.awt.Color(255, 255, 255));
        cuadroPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
        jScrollPane1.setBorder(null);
        jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        table.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][]{
                },
                new String[]{
                        "", "", "", ""
                }
        ));
        jScrollPane1.setViewportView(table);

        operadoresPanel.setBackground(new java.awt.Color(255, 255, 255));
        operadoresPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 1, true), "Operadores y variables"), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)));

        final String parentesisOperando = "No se permite colocar un operando inmediatamente tras abrir un parentesis!";
        final String operandoOperando = "No se permite colocar un operando inmediatamente despues de otro operando!";
        final String listSize0 = "La expresion de una tabla de verdad no puede iniciar con un operando, salvo la negacion!";

        negacionButton.setText("Negacion");
//        negacionButton.setMnemonic('n');
        negacionButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tableTitles.size() != 0) {
                    char[] array = tableTitles.get(tableTitles.size() - 1).toCharArray();
                    if (array[array.length - 1] == '(') {
                        tableTitles.add("0");
                        addTableColumn(null);
                    } else {
                        if (checkIsNumber(tableTitles.get(tableTitles.size() - 1))) {
                            JOptionPane.showMessageDialog(TruthTablePanel.this,
                                    operandoOperando, "",
                                    JOptionPane.WARNING_MESSAGE);
                        } else {
                            tableTitles.add("0");
                            addTableColumn(null);
                        }
                    }
                } else {
                    tableTitles.add("0");
                    addTableColumn(null);
                }
            }
        });

        conjuncionButton.setText("Conjuncion");
//        conjuncionButton.setMnemonic('j');
        conjuncionButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tableTitles.size() == 0) {
                    JOptionPane.showMessageDialog(TruthTablePanel.this,
                            listSize0, "",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    char[] array = tableTitles.get(tableTitles.size() - 1).toCharArray();
                    if (array[array.length - 1] == '(') {
                        JOptionPane.showMessageDialog(TruthTablePanel.this,
                                parentesisOperando, "",
                                JOptionPane.WARNING_MESSAGE);
                    } else {
                        if (checkIsNumber(tableTitles.get(tableTitles.size() - 1))) {
                            JOptionPane.showMessageDialog(TruthTablePanel.this,
                                    operandoOperando, "",
                                    JOptionPane.WARNING_MESSAGE);
                        } else {
                            tableTitles.add("7");
                            addTableColumn(null);
                        }
                    }
                }
            }
        });

        disyuncionIncButton.setText("Disyuncion inclusiva");
//        disyuncionIncButton.setMnemonic('d');
        disyuncionIncButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tableTitles.size() == 0) {
                    JOptionPane.showMessageDialog(TruthTablePanel.this,
                            listSize0, "",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    char[] array = tableTitles.get(tableTitles.size() - 1).toCharArray();
                    if (array[array.length - 1] == '(') {
                        JOptionPane.showMessageDialog(TruthTablePanel.this, parentesisOperando, "",
                                JOptionPane.WARNING_MESSAGE);
                    } else {
                        if (checkIsNumber(tableTitles.get(tableTitles.size() - 1))) {
                            JOptionPane.showMessageDialog(TruthTablePanel.this,
                                    operandoOperando, "",
                                    JOptionPane.WARNING_MESSAGE);
                        } else {
                            tableTitles.add("5");
                            addTableColumn(null);
                        }
                    }
                }
            }
        });

        disyuncionExcButton.setText("Disyuncion exclusiva");
//        disyuncionExcButton.setMnemonic('e');
        disyuncionExcButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tableTitles.size() == 0) {
                    JOptionPane.showMessageDialog(TruthTablePanel.this,
                            listSize0, "",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    char[] array = tableTitles.get(tableTitles.size() - 1).toCharArray();
                    if (array[array.length - 1] == '(') {
                        JOptionPane.showMessageDialog(TruthTablePanel.this,
                                parentesisOperando, "",
                                JOptionPane.WARNING_MESSAGE);
                    } else {
                        if (checkIsNumber(tableTitles.get(tableTitles.size() - 1))) {
                            JOptionPane.showMessageDialog(TruthTablePanel.this,
                                    operandoOperando, "",
                                    JOptionPane.WARNING_MESSAGE);
                        } else {
                            tableTitles.add("3");
                            addTableColumn(null);
                        }
                    }
                }
            }
        });

        condicionalButton.setText("Condicional");
//        condicionalButton.setMnemonic('c');
        condicionalButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tableTitles.size() == 0) {
                    JOptionPane.showMessageDialog(TruthTablePanel.this,
                            listSize0, "",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    char[] array = tableTitles.get(tableTitles.size() - 1).toCharArray();
                    if (array[array.length - 1] == '(') {
                        JOptionPane.showMessageDialog(TruthTablePanel.this,
                                parentesisOperando, "",
                                JOptionPane.WARNING_MESSAGE);
                    } else {
                        if (checkIsNumber(tableTitles.get(tableTitles.size() - 1))) {
                            JOptionPane.showMessageDialog(TruthTablePanel.this,
                                    operandoOperando, "",
                                    JOptionPane.WARNING_MESSAGE);
                        } else {
                            tableTitles.add("1");
                            addTableColumn(null);
                        }
                    }
                }
            }
        });

        bicondicionalButton.setText("Bicondicional");
//        bicondicionalButton.setMnemonic('b');
        bicondicionalButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tableTitles.size() == 0) {
                    JOptionPane.showMessageDialog(TruthTablePanel.this,
                            listSize0, "",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    char[] array = tableTitles.get(tableTitles.size() - 1).toCharArray();
                    if (array[array.length - 1] == '(') {
                        JOptionPane.showMessageDialog(TruthTablePanel.this,
                                parentesisOperando, "",
                                JOptionPane.WARNING_MESSAGE);
                    } else {
                        if (checkIsNumber(tableTitles.get(tableTitles.size() - 1))) {
                            JOptionPane.showMessageDialog(TruthTablePanel.this,
                                    operandoOperando, "",
                                    JOptionPane.WARNING_MESSAGE);
                        } else {
                            tableTitles.add("2");
                            addTableColumn(null);
                        }
                    }
                }
            }
        });

        negacionConjuntaButton.setText("Negacion conjunta");
//        negacionConjuntaButton.setMnemonic('g');
        negacionConjuntaButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tableTitles.size() == 0) {
                    JOptionPane.showMessageDialog(TruthTablePanel.this,
                            listSize0, "",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    char[] array = tableTitles.get(tableTitles.size() - 1).toCharArray();
                    if (array[array.length - 1] == '(') {
                        JOptionPane.showMessageDialog(TruthTablePanel.this, parentesisOperando, "",
                                JOptionPane.WARNING_MESSAGE);
                    } else {
                        if (checkIsNumber(tableTitles.get(tableTitles.size() - 1))) {
                            JOptionPane.showMessageDialog(TruthTablePanel.this,
                                    operandoOperando, "",
                                    JOptionPane.WARNING_MESSAGE);
                        } else {
                            tableTitles.add("4");
                            addTableColumn(null);
                        }
                    }
                }
            }
        });

        incompatibilidadButton.setText("Incompatibilidad");
//        incompatibilidadButton.setMnemonic('i');
        incompatibilidadButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tableTitles.size() == 0) {
                    JOptionPane.showMessageDialog(TruthTablePanel.this,
                            listSize0, "",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    char[] array = tableTitles.get(tableTitles.size() - 1).toCharArray();
                    if (array[array.length - 1] == '(') {
                        JOptionPane.showMessageDialog(TruthTablePanel.this,
                                parentesisOperando, "",
                                JOptionPane.WARNING_MESSAGE);
                    } else {
                        if (checkIsNumber(tableTitles.get(tableTitles.size() - 1))) {
                            JOptionPane.showMessageDialog(TruthTablePanel.this,
                                    operandoOperando, "",
                                    JOptionPane.WARNING_MESSAGE);
                        } else {
                            tableTitles.add("6");
                            addTableColumn(null);
                        }
                    }
                }
            }
        });

        variableIngresarLabel.setText("Ingresar variable o parentesis:");

        acceptButton.setText("Aceptar");
        acceptButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String input = inputTextField.getText();
                int first = (input.replace("(", "")).length();
                int second = (input.replace(")", "")).length();
                if (!(first == 1 || second == 1 || first == 0 || second == 0)) {
                    JOptionPane.showMessageDialog(TruthTablePanel.this,
                            "No se permite el uso de mas de un caracter para designar proposiciones atomicas!", "", JOptionPane.WARNING_MESSAGE);
                } else {
                    if (checkIsNumber(input)) {
                        JOptionPane.showMessageDialog(TruthTablePanel.this,
                                "No se permite el uso de numeros como proposiciones atomicas", "", JOptionPane.WARNING_MESSAGE);
                    } else {
                        if (tableTitles.size() != 0) {
                            char[] array = tableTitles.get(tableTitles.size() - 1).toCharArray();
                            if (input.charAt(0) == ')') {
                                if (array[array.length - 1] == '(') {
                                    JOptionPane.showMessageDialog(TruthTablePanel.this,
                                            "La expresion () no posee sentido!", "", JOptionPane.WARNING_MESSAGE);
                                } else {
                                    if (checkIsNumber("" + array[array.length - 1])) {
                                        JOptionPane.showMessageDialog(TruthTablePanel.this,
                                                "No tiene sentido colocar un parentesis detras de un operando!", "",
                                                JOptionPane.WARNING_MESSAGE);
                                    } else {
                                        input = tableTitles.get(tableTitles.size() - 1).concat(input);
                                        tableTitles.set(tableTitles.size() - 1, input);
                                    }
                                }
                            } else {
                                if (array[array.length - 1] == '(') {//
                                    input = tableTitles.get(tableTitles.size() - 1).concat(input);
                                    tableTitles.set(tableTitles.size() - 1, input);
                                } else {
                                    if (!checkIsNumber("" + input) && !checkIsNumber("" + array[array.length - 1])) {
                                        JOptionPane.showMessageDialog(TruthTablePanel.this,
                                                "No tiene sentido colocar dos proposiciones atomicas seguidas!", "",
                                                JOptionPane.WARNING_MESSAGE);
                                    } else {
                                        if (input.contains("(")) {
                                            tableTitles.set(tableTitles.size() - 1, tableTitles.get(tableTitles.size() - 1).concat(getParenthesis(input)));
                                        }
                                        input = input.replace("(", "");
                                        if (!input.equals("")) {
                                            tableTitles.add(input);
                                        }
                                    }
                                }
                            }
                        } else {
                            System.out.println("XXX");
                            tableTitles.add(input);
                        }
                    }
                    addTableColumn(null);
                }
                inputTextField.setText("");
            }
        });

        jSeparator1.setForeground(new java.awt.Color(0, 0, 0));

        calcularTabla.setText("Calcular tabla");
        calcularTabla.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                truthTable = new TruthTable(buildExpression());
                addTableColumn(truthTable.getResult());
            }
        });

        resetButton.setText("Resetear");
        resetButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                tableTitles = new ArrayList<String>();
                addTableColumn(null);
            }
        });

        jSeparator2.setForeground(new java.awt.Color(0, 0, 0));

        javax.swing.GroupLayout operadoresPanelLayout = new javax.swing.GroupLayout(operadoresPanel);
        operadoresPanel.setLayout(operadoresPanelLayout);
        operadoresPanelLayout.setHorizontalGroup(
                operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(operadoresPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 616, Short.MAX_VALUE)
                                .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 616, Short.MAX_VALUE)
                                .addGroup(operadoresPanelLayout.createSequentialGroup()
                                        .addGroup(operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(conjuncionButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addComponent(negacionButton, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE))
                                                .addComponent(variableIngresarLabel))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                                        .addGroup(operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(inputTextField, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(disyuncionIncButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(disyuncionExcButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGap(34, 34, 34)
                                        .addGroup(operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(acceptButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(condicionalButton, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                                                .addComponent(bicondicionalButton, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE))
                                        .addGap(33, 33, 33)
                                        .addGroup(operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(incompatibilidadButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(negacionConjuntaButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, operadoresPanelLayout.createSequentialGroup()
                                .addComponent(calcularTabla, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(resetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
        );
        operadoresPanelLayout.setVerticalGroup(
                operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(operadoresPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(operadoresPanelLayout.createSequentialGroup()
                                        .addComponent(disyuncionIncButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(disyuncionExcButton))
                                .addGroup(operadoresPanelLayout.createSequentialGroup()
                                        .addComponent(condicionalButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(bicondicionalButton))
                                .addGroup(operadoresPanelLayout.createSequentialGroup()
                                        .addComponent(negacionButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(conjuncionButton))
                                .addGroup(operadoresPanelLayout.createSequentialGroup()
                                .addComponent(negacionConjuntaButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(incompatibilidadButton)))
                        .addGap(12, 12, 12)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(inputTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(variableIngresarLabel)
                                .addComponent(acceptButton))
                        .addGap(9, 9, 9)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addGroup(operadoresPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(calcularTabla)
                        .addComponent(resetButton)))
        );

        javax.swing.GroupLayout cuadroPanelLayout = new javax.swing.GroupLayout(cuadroPanel);
        cuadroPanel.setLayout(cuadroPanelLayout);
        cuadroPanelLayout.setHorizontalGroup(
                cuadroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 660, Short.MAX_VALUE)
                        .addGroup(cuadroPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(operadoresPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        cuadroPanelLayout.setVerticalGroup(
                cuadroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(cuadroPanelLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(operadoresPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(cuadroPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(cuadroPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                        .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
        );
    }

    private void addTableColumn(Object[][] content) {
        if (content == null) {
            content = new Object[][]{};
        }
        table.setModel(new javax.swing.table.DefaultTableModel(
                content, tableTitles.toArray()
        ));
        JLabel label;
        String current;
        String parenthesis;
        for (int j = 0; j < tableTitles.size(); j++) {
//            table.getColumnModel().getColumn(j).setMinWidth(700);//todo
            label = new JLabel();
            label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
            current = tableTitles.get(j).replace("(", "");
            current = current.replace(")", "");
            parenthesis = getParenthesis(tableTitles.get(j));
            table.getColumnModel().getColumn(j).setHeaderRenderer(new JComponentCellRenderer());
            if (current.equalsIgnoreCase("0")) {
                label.setText(parenthesis);
                label.setIcon(Utiles.createImageIcon("/gui/images/truth_table/negacion.gif"));
                table.getColumnModel().getColumn(j).setHeaderValue(label);
            } else {
                if (current.equalsIgnoreCase("1")) {
                    label.setText(parenthesis);
                    label.setIcon(Utiles.createImageIcon("/gui/images/truth_table/condicional.gif"));
                    table.getColumnModel().getColumn(j).setHeaderValue(label);
                } else {
                    if (current.equalsIgnoreCase("2")) {
                        label.setText(parenthesis);
                        label.setIcon(Utiles.createImageIcon("/gui/images/truth_table/bicondicional.gif"));
                        table.getColumnModel().getColumn(j).setHeaderValue(label);
                    } else {
                        if (current.equalsIgnoreCase("3")) {
                            label.setText(parenthesis);
                            label.setIcon(Utiles.createImageIcon("/gui/images/truth_table/disyuncionExclusiva.gif"));
                            table.getColumnModel().getColumn(j).setHeaderValue(label);
                        } else {
                            if (current.equalsIgnoreCase("4")) {
                                label.setText(parenthesis);
                                label.setIcon(Utiles.createImageIcon("/gui/images/truth_table/negacionConjunta.gif"));
                                table.getColumnModel().getColumn(j).setHeaderValue(label);
                            } else {
                                if (current.equalsIgnoreCase("5")) {
                                    label.setText(parenthesis);
                                    label.setIcon(Utiles.createImageIcon("/gui/images/truth_table/disyuncionInclusiva.gif"));
                                    table.getColumnModel().getColumn(j).setHeaderValue(label);
                                } else {
                                    if (current.equalsIgnoreCase("6")) {
                                        label.setText(parenthesis);
                                        label.setIcon(Utiles.createImageIcon("/gui/images/truth_table/incompatible.gif"));
                                        table.getColumnModel().getColumn(j).setHeaderValue(label);
                                    } else {
                                        if (current.equalsIgnoreCase("7")) {
                                            label.setText(parenthesis);
                                            label.setIcon(Utiles.createImageIcon("/gui/images/truth_table/conjuncion.gif"));
                                            table.getColumnModel().getColumn(j).setHeaderValue(label);
                                        } else {
                                            label.setText(" " + tableTitles.get(j));
                                            label.setFont(new Font("Tahoma", 1, 16));
                                            table.getColumnModel().getColumn(j).setHeaderValue(label);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            table.getTableHeader().revalidate();
//            resizeTable();//todo
        }
    }

    private void setResult() {
        //todo
    }

    private boolean checkIsNumber(String input) {
        char[] array = input.toCharArray();
        char character;
        for (int j = 0; j < array.length; j++) {
            character = array[j];
            if (character == '0' || character == '1' || character == '2' || character == '3' || character == '4' || character == '5' ||
                    character == '6' || character == '7' || character == '8' || character == '9') {
                return true;
            }
        }
        return false;
    }

    //no considera la negacion
    private boolean checkIsOperand(String input) {
        char[] array = input.toCharArray();
        char character;
        for (int j = 0; j < array.length; j++) {
            character = array[j];
            if (character == '1' || character == '2' || character == '3' || character == '4' || character == '5' ||
                    character == '6' || character == '7') {
                return true;
            }
        }
        return false;
    }

    private void resizeTable() {
        System.out.println("size: " + (tableTitles.size() * 20));
        int width = (tableTitles.size() * 20);
        int height = (int) table.getSize().getHeight();
        if ((tableTitles.size() * 700) > 711) {
            table.setMinimumSize(new Dimension(width, height));//todo opcion1
            table.setPreferredScrollableViewportSize(new Dimension(width, height));//todo opcion2
            jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        }
    }

    private String buildExpression() {
        int size = tableTitles.size();
        StringBuffer stringBuffer = new StringBuffer();
        for (int j = 0; j < size; j++) {
            stringBuffer.append(tableTitles.get(j));
        }
        return stringBuffer.toString();
    }

    private String getParenthesis(String current) {
        char parenthesisOpen = '(';
        char parenthesisClose = ')';
        char[] array = current.toCharArray();
        StringBuffer stringBuffer = new StringBuffer();
        for (int j = 0; j < array.length; j++) {
            if (array[j] == parenthesisOpen || array[j] == parenthesisClose) {
                stringBuffer.append("" + array[j]);
            }
        }
        return stringBuffer.toString();
    }
}
